<template>
  <el-dialog v-model="dialogVisible" title="编辑小程序链接">
    <el-form :model="formData" ref="formRef" label-width="80px">
      <el-form-item label="链接">
        <el-input v-model="formData.link" type="textarea" :rows="4" placeholder="请输入链接" />
      </el-form-item>
      <el-form-item label="链接备注">
        <el-input v-model="formData.linkRemark" placeholder="请输入链接备注" :maxlength="15" show-word-limit />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="handleConfirm">确定</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { ElMessage } from 'element-plus';

// 控制弹窗显示与隐藏
const dialogVisible = ref(false);
// 表单数据
const formData = ref({
  link: '',
  linkRemark: ''
});
// 表单引用
const formRef = ref(null);

// 确定按钮点击事件
const handleConfirm = () => {
  if (!formRef.value) return;
  // 这里可以添加提交表单数据的逻辑
  updateLink();
  dialogVisible.value = false;
};
const openDialog = (data: any) => {
  Object.assign(formData.value, data);
  dialogVisible.value = true;
};
const closeDialog = () => {
  dialogVisible.value = false;
};
const emit = defineEmits(['updateLink']);

const updateLink = () => {
  emit('updateLink', formData.value, 'MODIFY');
};

// 暴露打开弹窗的方法，供父组件调用
defineExpose({
  openDialog,
  closeDialog
});
</script>

<style scoped>
.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
</style>
